﻿package com.tudou.log
{
    import flash.events.*;
    import flash.net.*;
    import flash.utils.*;

    public class Logger extends Object implements ILogger
    {
        private var conn:LocalConnection;
        private static var ID:Number;
        private static var _instance:Logger;

        public function Logger()
        {
            conn = new LocalConnection();
            conn.allowDomain("*");
            conn.addEventListener(StatusEvent.STATUS, onLncStatus, false, 0, true);
            ID = Math.ceil(Math.random() * 10000);
            return;
        }// end function

        public function debug(param1:Object, ... args) : void
        {
            print("debug", args, 1, param1);
            return;
        }// end function

        private function onLncStatus(event:StatusEvent) : void
        {
            return;
        }// end function

        private function print(param1:String, param2:Array, param3:Number, param4:Object) : void
        {
            var _loc_5:String = "";
            var _loc_6:int = 0;
            while (_loc_6 < param2.length)
            {
                
                _loc_5 = _loc_5 + (param2[_loc_6] + " ");
                _loc_6++;
            }
            _loc_5 = "[" + param1 + "]-[" + getQualifiedClassName(param4) + "]-[" + _loc_5 + "]";
            var _loc_7:* = /<""</g;
            var _loc_8:* = />"">/g;
            _loc_5 = _loc_5.replace(_loc_7, "&lt;");
            _loc_5 = _loc_5.replace(_loc_8, "&gt;");
            conn.send("_debug_client", "print", _loc_5, param3, ID);
            return;
        }// end function

        public function warn(param1:Object, ... args) : void
        {
            print("warn", args, 2, param1);
            return;
        }// end function

        public function error(param1:Object, ... args) : void
        {
            print("error", args, 3, param1);
            return;
        }// end function

        public static function getInst() : Logger
        {
            if (_instance == null)
            {
                _instance = new Logger;
            }
            return _instance;
        }// end function

    }
}
